package com.xxx.config;

//import com.xxx.service.MyTransactionListener;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.TransactionMQProducer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rocketmq事务消息①
 */
@Configuration
public class RocketMQConfig {

    @Value("${rocketmq.name-server}")
    private String nameServer;
    @Value("${rocketmq.producer.group}")
    private String group;

//    // 实例化TransactionMQProducer
//    @Bean
//    public TransactionMQProducer transactionMQProducer(MyTransactionListener myTransactionListener) throws MQClientException {
//        // 创建事务消息生产者
//        TransactionMQProducer producer = new TransactionMQProducer(group);
//        producer.setNamesrvAddr(nameServer); // 设置NameServer地址
//        producer.setRetryTimesWhenSendAsyncFailed(0);  // 设置异步发送消息失败时的最大重试次数，默认值：2 次（即总共尝试 3 次：1次初始发送 + 2次重试）
//        producer.setTransactionListener(myTransactionListener);  // 事务监听器
//        producer.start();
//        return producer;
//    }

}
